package com.zablert.mainactivity.teaching;

import android.graphics.Color;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;

import com.zablert.mainactivity.R;

import java.util.ArrayList;
import java.util.List;

public class LearningAdapter extends BaseAdapter {
    private List<LearningParam> data = new ArrayList<>();

    public void setData(List<LearningParam> gtp) {
        data.clear();
        if (gtp != null) {
            data.addAll(gtp);
        }
    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_learning;
    }

    @Override
    public void onBindViewHolder(@NonNull BaseViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        holder.setText(R.id.tv_title, "Title " + position).setTextColor(R.id.tv_title, Color.parseColor("#FF0000")).setTextSize(R.id.tv_title, 12);
        holder.setText(R.id.tv_description, "Description " + position);
        holder.itemView.findViewById(R.id.tv_title).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), "啊，你轻轻的点了" + position + ",真棒", Toast.LENGTH_SHORT).show();
            }
        });
        holder.itemView.findViewById(R.id.tv_description).setOnClickListener(onClickListener);
    }

    private View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
//            Toast.makeText(v.getContext(), "啊，你轻轻的点了" + position + ",真棒", Toast.LENGTH_SHORT).show();
        }
    };
}
